/*
 * CS 441-541: Artificial Intelligence Fall 2012
 * Date: October-28-2012
 * @author Loc Ngo
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConnectThree.java
 *
 * Created on Oct 22, 2012, 12:31:32 PM
 */
package connect.three;
import java.util.Vector;
import javax.swing.SwingWorker;


  class Task extends SwingWorker<Void, Void> {
    ConnectThree ct;
    public Task(ConnectThree ct)
    {
        this.ct = ct;
    }
    /*
     * Main task. Executed in background thread.
     */
    @Override
    public Void doInBackground() {
        State initState = new State(ConnectThreeUtility.cloneBoard(ct.Board));
        ct.waitingjLabel.setVisible(true);
        ct.waitingjProgressBar.setVisible(true);
        ct.DropjButton1.setEnabled(false);
        ct.DropjButton2.setEnabled(false);
        ct.DropjButton3.setEnabled(false);
        ct.runAI(initState);
        ct.DropjButton1.setEnabled(true);
        ct.DropjButton2.setEnabled(true);
        ct.DropjButton3.setEnabled(true);
        ct.waitingjLabel.setVisible(false);
        ct.waitingjProgressBar.setVisible(false);
     
      return null;
    }

    /*
     * Executed in event dispatch thread
     */
    public void done() {
        
    }
  }

class ConnectThreeUtility
{
    static final int AI_WIN = 1000000000;
    static final int PLAYER_WIN = -1000000000;
    static int[][] cloneBoard(int[][] Board)
    {
        int[][] newBoard = new int[10][];
        for(int i=0;i<10;i++){
            newBoard[i] = new int[3];
            System.arraycopy(Board[i], 0, newBoard[i], 0, 3);
        }
        return newBoard;
    }
}

class State{
    
    int h_chosen_circle_row;
    int h_chosen_circle_column;
    private int[][] Board;
    
    public State(int[][] Board){
        this.Board = Board;
    }
    
    public void display(){
        for(int i=0;i<=9;i++){
            for(int j=0;j<=2;j++)
                System.out.print(Board[i][j]+ " ");
            System.out.println();
        }
    }
    
    public int getScore(){
        /*
         * get the heuristic score for a particular board
         * h(s) = V(AI) - V(Player), in which
         * V(AI) = 1000000 * numberOf3Circles + 1000 * numberOf2Circles + 100 * numberOf1Connect 
         * V(Player) is calculated as same as V(AI)
         * More details:
         *      + numberOf3Circles: 3 circles with the same color in array of 3 circles
         *      + numberOf2Circles: 2 circles with the same color & 1 empty circle in array of 3 circles
         *          for example:
         *                          ---121-- => not count for player
         *                          ---101-- => count for player
         *                          
         *      + numberOf1Circle: 1 circle & 2 empty circles in an array of 3 circles 
         *          for example:
         *                          ---102-- => not count for player
         * 
         *                          --0-----  
         *                          ---1---- => count
         *                          ----0---
         */
        
        int AI_numberOf3Circles = 0;
        int AI_numberOf2Circles = 0;
        int AI_numberOf1Circle = 0;
        int AIScore;
        
        int Player_numberOf3Circles = 0;
        int Player_numberOf2Circles = 0;
        int Player_numberOf1Circle = 0;
        int PlayerScore;
        
        
        //scan the board for score
        for(int i=9;i>=0;i--)
            for(int j=0;j<3;j++)
            {
                //left to right
                if(j+1<3 && j+2<3){
                    if(this.Board[i][j] + this.Board[i][j+1] + this.Board[i][j+2] == 3)
                        Player_numberOf3Circles++;
                
                    if(this.Board[i][j] + this.Board[i][j+1] + this.Board[i][j+2] == 300)
                        AI_numberOf3Circles++;
                    
                    if(this.Board[i][j] + this.Board[i][j+1] + this.Board[i][j+2] == 2)
                        Player_numberOf2Circles++;
                
                    if(this.Board[i][j] + this.Board[i][j+1] + this.Board[i][j+2] == 200)
                        AI_numberOf2Circles++;
                    
                    if(this.Board[i][j] + this.Board[i][j+1] + this.Board[i][j+2] == 1)
                        Player_numberOf1Circle++;
                
                    if(this.Board[i][j] + this.Board[i][j+1] + this.Board[i][j+2] == 100)
                        AI_numberOf1Circle++;
                }
                
                //down to up
                if(i-1>=0 && i-2>=0){
                    if(this.Board[i][j] + this.Board[i-1][j] + this.Board[i-2][j] == 3)
                        Player_numberOf3Circles++;
                
                    if(this.Board[i][j] + this.Board[i-1][j] + this.Board[i-2][j] == 300)
                        AI_numberOf3Circles++;
                    
                    if(this.Board[i][j] + this.Board[i-1][j] + this.Board[i-2][j] == 2)
                        Player_numberOf2Circles++;
                
                    if(this.Board[i][j] + this.Board[i-1][j] + this.Board[i-2][j] == 200)
                        AI_numberOf2Circles++;
                    
                    if(this.Board[i][j] + this.Board[i-1][j] + this.Board[i-2][j] == 1)
                        Player_numberOf1Circle++;
                
                    if(this.Board[i][j] + this.Board[i-1][j] + this.Board[i-2][j] == 100)
                        AI_numberOf1Circle++;
                }
                
                //bottom-right to upper-left
                if(i-1>=0 && j-1>=0 && i-2>=0&&j-2>=0){
                    if(this.Board[i][j] + this.Board[i-1][j-1] + this.Board[i-2][j-2] == 3)
                        Player_numberOf3Circles++;
                
                    if(this.Board[i][j] + this.Board[i-1][j-1] + this.Board[i-2][j-2] == 300)
                        AI_numberOf3Circles++;
                    
                    if(this.Board[i][j] + this.Board[i-1][j-1] + this.Board[i-2][j-2] == 2)
                        Player_numberOf2Circles++;
                
                    if(this.Board[i][j] + this.Board[i-1][j-1] + this.Board[i-2][j-2] == 200)
                        AI_numberOf2Circles++;
                    
                    if(this.Board[i][j] + this.Board[i-1][j-1] + this.Board[i-2][j-2] == 1)
                        Player_numberOf1Circle++;
                
                    if(this.Board[i][j] + this.Board[i-1][j-1] + this.Board[i-2][j-2] == 100)
                        AI_numberOf1Circle++;
                }
                
                //bottom-left to upper-right
                if(i-1>=0 && j+1<3 && i-2>=0&&j+2<3){
                    if(this.Board[i][j] + this.Board[i-1][j+1] + this.Board[i-2][j+2] == 3)
                        Player_numberOf3Circles++;
                
                    if(this.Board[i][j] + this.Board[i-1][j+1] + this.Board[i-2][j+2] == 300)
                        AI_numberOf3Circles++;
                    
                    if(this.Board[i][j] + this.Board[i-1][j+1] + this.Board[i-2][j+2] == 2)
                        Player_numberOf2Circles++;
                
                    if(this.Board[i][j] + this.Board[i-1][j+1] + this.Board[i-2][j+2] == 200)
                        AI_numberOf2Circles++;
                    
                    if(this.Board[i][j] + this.Board[i-1][j+1] + this.Board[i-2][j+2] == 1)
                        Player_numberOf1Circle++;
                
                    if(this.Board[i][j] + this.Board[i-1][j+1] + this.Board[i-2][j+2] == 100)
                        AI_numberOf1Circle++;
                }
            }
        if(Player_numberOf3Circles>=1)
            return ConnectThreeUtility.PLAYER_WIN;
        if(AI_numberOf3Circles>=1)
            return ConnectThreeUtility.AI_WIN;
        AIScore = AI_numberOf2Circles*1000 + AI_numberOf1Circle*100;
        PlayerScore = Player_numberOf2Circles*1000 + Player_numberOf1Circle*100;
        return AIScore - PlayerScore;
    }
   
    public Vector<State> getAllNeighborStates(String step)
    {
        Vector<State> VS = new Vector<State>();
        for(int j=0;j<3;j++)
            for(int i=9;i>=0;i--)
                if(this.Board[i][j]==0)
                {
                    int[][] newBoard = ConnectThreeUtility.cloneBoard(this.Board);
                    if(step.compareTo("max")==0) //AI turn
                        newBoard[i][j] = 100;
                    else //Player turn
                        newBoard[i][j] = 1;
                    //add new State
                    State newState = new State(newBoard);
                   
                    newState.h_chosen_circle_row = i;
                    newState.h_chosen_circle_column = j;
                    VS.add(newState);
                    break;
                }
        return VS;
    }
}

public class ConnectThree extends javax.swing.JFrame {
    private Task task;
    private javax.swing.JLabel[][] LabelState;
    /* not set      0
     * player mark  1
     * AI mark      100
     */
    public int[][] Board;
    private int depth; //Minimax Depth
    private int AI_nextstep_row;
    private int AI_nextstep_column;
    
    /** Creates new form ConnectThree */
    public ConnectThree() {
        initComponents();
        this.LabelState = new javax.swing.JLabel[10][];
        this.Board = new int[10][];
        for(int i=0;i<10;i++){
            this.LabelState[i] = new javax.swing.JLabel[3];
            this.Board[i] = new int[3];
        }
        
        this.LabelState[0][0] = this.CirclejLabel0;
        this.LabelState[0][1] = this.CirclejLabel1;
        this.LabelState[0][2] = this.CirclejLabel2;
        this.LabelState[1][0] = this.CirclejLabel3;
        this.LabelState[1][1] = this.CirclejLabel4;
        this.LabelState[1][2] = this.CirclejLabel5;
        this.LabelState[2][0] = this.CirclejLabel6;
        this.LabelState[2][1] = this.CirclejLabel7;
        this.LabelState[2][2] = this.CirclejLabel8;
        this.LabelState[3][0] = this.CirclejLabel9;
        this.LabelState[3][1] = this.CirclejLabel10;
        this.LabelState[3][2] = this.CirclejLabel11;
        this.LabelState[4][0] = this.CirclejLabel12;
        this.LabelState[4][1] = this.CirclejLabel13;
        this.LabelState[4][2] = this.CirclejLabel14;
        this.LabelState[5][0] = this.CirclejLabel15;
        this.LabelState[5][1] = this.CirclejLabel16;
        this.LabelState[5][2] = this.CirclejLabel17;
        this.LabelState[6][0] = this.CirclejLabel18;
        this.LabelState[6][1] = this.CirclejLabel19;
        this.LabelState[6][2] = this.CirclejLabel20;
        this.LabelState[7][0] = this.CirclejLabel21;
        this.LabelState[7][1] = this.CirclejLabel22;
        this.LabelState[7][2] = this.CirclejLabel23;
        this.LabelState[8][0] = this.CirclejLabel24;
        this.LabelState[8][1] = this.CirclejLabel25;
        this.LabelState[8][2] = this.CirclejLabel26;
        this.LabelState[9][0] = this.CirclejLabel27;
        this.LabelState[9][1] = this.CirclejLabel28;
        this.LabelState[9][2] = this.CirclejLabel29;
        
        this.DropjPanel.setVisible(false);
        this.StatejPanel.setVisible(false);
        this.waitingjLabel.setVisible(false);
        this.waitingjProgressBar.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PlayFirstButtonGroup = new javax.swing.ButtonGroup();
        AIConfigButtonGroup = new javax.swing.ButtonGroup();
        StatejPanel = new javax.swing.JPanel();
        CirclejLabel0 = new javax.swing.JLabel();
        CirclejLabel1 = new javax.swing.JLabel();
        CirclejLabel2 = new javax.swing.JLabel();
        CirclejLabel3 = new javax.swing.JLabel();
        CirclejLabel4 = new javax.swing.JLabel();
        CirclejLabel5 = new javax.swing.JLabel();
        CirclejLabel6 = new javax.swing.JLabel();
        CirclejLabel7 = new javax.swing.JLabel();
        CirclejLabel8 = new javax.swing.JLabel();
        CirclejLabel9 = new javax.swing.JLabel();
        CirclejLabel10 = new javax.swing.JLabel();
        CirclejLabel11 = new javax.swing.JLabel();
        CirclejLabel12 = new javax.swing.JLabel();
        CirclejLabel13 = new javax.swing.JLabel();
        CirclejLabel14 = new javax.swing.JLabel();
        CirclejLabel15 = new javax.swing.JLabel();
        CirclejLabel16 = new javax.swing.JLabel();
        CirclejLabel17 = new javax.swing.JLabel();
        CirclejLabel18 = new javax.swing.JLabel();
        CirclejLabel19 = new javax.swing.JLabel();
        CirclejLabel20 = new javax.swing.JLabel();
        CirclejLabel21 = new javax.swing.JLabel();
        CirclejLabel22 = new javax.swing.JLabel();
        CirclejLabel23 = new javax.swing.JLabel();
        CirclejLabel24 = new javax.swing.JLabel();
        CirclejLabel25 = new javax.swing.JLabel();
        CirclejLabel26 = new javax.swing.JLabel();
        CirclejLabel27 = new javax.swing.JLabel();
        CirclejLabel28 = new javax.swing.JLabel();
        CirclejLabel29 = new javax.swing.JLabel();
        DropjPanel = new javax.swing.JPanel();
        DropjButton1 = new javax.swing.JButton();
        DropjButton2 = new javax.swing.JButton();
        DropjButton3 = new javax.swing.JButton();
        AIConfigJPanel = new javax.swing.JPanel();
        AIjRadioButton = new javax.swing.JRadioButton();
        PlayerjRadioButton = new javax.swing.JRadioButton();
        StartjButton = new javax.swing.JButton();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        EasyjRadioButton = new javax.swing.JRadioButton();
        MediumjRadioButton = new javax.swing.JRadioButton();
        HardjRadioButton = new javax.swing.JRadioButton();
        ExtremejRadioButton = new javax.swing.JRadioButton();
        TouristjRadioButton = new javax.swing.JRadioButton();
        Status = new javax.swing.JLabel();
        ModejLabel = new javax.swing.JLabel();
        waitingjProgressBar = new javax.swing.JProgressBar();
        waitingjLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Connect Three Game");

        StatejPanel.setBackground(new java.awt.Color(255, 255, 255));

        CirclejLabel0.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel21.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel22.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel23.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel24.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel25.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel26.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel27.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel28.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        CirclejLabel29.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg"))); // NOI18N

        javax.swing.GroupLayout StatejPanelLayout = new javax.swing.GroupLayout(StatejPanel);
        StatejPanel.setLayout(StatejPanelLayout);
        StatejPanelLayout.setHorizontalGroup(
            StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(StatejPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(CirclejLabel15)
                        .addComponent(CirclejLabel18)
                        .addComponent(CirclejLabel21)
                        .addComponent(CirclejLabel24)
                        .addComponent(CirclejLabel27))
                    .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(CirclejLabel9)
                        .addComponent(CirclejLabel12))
                    .addComponent(CirclejLabel6)
                    .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(CirclejLabel0)
                        .addComponent(CirclejLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(CirclejLabel16)
                            .addComponent(CirclejLabel19)
                            .addComponent(CirclejLabel22)
                            .addComponent(CirclejLabel25)
                            .addComponent(CirclejLabel28))
                        .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(CirclejLabel10)
                            .addComponent(CirclejLabel13))
                        .addComponent(CirclejLabel7)
                        .addComponent(CirclejLabel1))
                    .addComponent(CirclejLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(CirclejLabel17)
                        .addComponent(CirclejLabel20)
                        .addComponent(CirclejLabel23)
                        .addComponent(CirclejLabel26)
                        .addComponent(CirclejLabel29))
                    .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(CirclejLabel11)
                        .addComponent(CirclejLabel14))
                    .addComponent(CirclejLabel8)
                    .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(CirclejLabel2)
                        .addComponent(CirclejLabel5)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        StatejPanelLayout.setVerticalGroup(
            StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, StatejPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(StatejPanelLayout.createSequentialGroup()
                        .addComponent(CirclejLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel23)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel26)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CirclejLabel29))
                    .addGroup(StatejPanelLayout.createSequentialGroup()
                        .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(StatejPanelLayout.createSequentialGroup()
                                .addComponent(CirclejLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(CirclejLabel4))
                            .addGroup(StatejPanelLayout.createSequentialGroup()
                                .addComponent(CirclejLabel0)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel3)))
                        .addGroup(StatejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(StatejPanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel21)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel24)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel27))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, StatejPanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel19)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel25)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CirclejLabel28)))))
                .addContainerGap())
        );

        DropjButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/drop.png"))); // NOI18N
        DropjButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DropjButton1ActionPerformed(evt);
            }
        });

        DropjButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/drop.png"))); // NOI18N
        DropjButton2.setMargin(new java.awt.Insets(3, 14, 2, 14));
        DropjButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DropjButton2ActionPerformed(evt);
            }
        });

        DropjButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/drop.png"))); // NOI18N
        DropjButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DropjButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout DropjPanelLayout = new javax.swing.GroupLayout(DropjPanel);
        DropjPanel.setLayout(DropjPanelLayout);
        DropjPanelLayout.setHorizontalGroup(
            DropjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DropjPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(DropjButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(DropjButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(DropjButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        DropjPanelLayout.setVerticalGroup(
            DropjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DropjPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(DropjPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(DropjButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DropjButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DropjButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        AIConfigJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Connect Three Options"));

        PlayFirstButtonGroup.add(AIjRadioButton);
        AIjRadioButton.setSelected(true);
        AIjRadioButton.setText("AI");
        AIjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AIjRadioButtonActionPerformed(evt);
            }
        });

        PlayFirstButtonGroup.add(PlayerjRadioButton);
        PlayerjRadioButton.setText("Player");

        StartjButton.setText("Start");
        StartjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StartjButtonActionPerformed(evt);
            }
        });

        jLabel31.setText("Who play first ?");

        jLabel32.setText("AI Configuration");

        AIConfigButtonGroup.add(EasyjRadioButton);
        EasyjRadioButton.setText("Easy");
        EasyjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EasyjRadioButtonActionPerformed(evt);
            }
        });

        AIConfigButtonGroup.add(MediumjRadioButton);
        MediumjRadioButton.setText("Medium");

        AIConfigButtonGroup.add(HardjRadioButton);
        HardjRadioButton.setText("Hard");

        AIConfigButtonGroup.add(ExtremejRadioButton);
        ExtremejRadioButton.setSelected(true);
        ExtremejRadioButton.setText("Extreme");

        AIConfigButtonGroup.add(TouristjRadioButton);
        TouristjRadioButton.setText("Tourist");
        TouristjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TouristjRadioButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout AIConfigJPanelLayout = new javax.swing.GroupLayout(AIConfigJPanel);
        AIConfigJPanel.setLayout(AIConfigJPanelLayout);
        AIConfigJPanelLayout.setHorizontalGroup(
            AIConfigJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AIConfigJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(AIConfigJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TouristjRadioButton)
                    .addComponent(ExtremejRadioButton)
                    .addComponent(HardjRadioButton)
                    .addComponent(EasyjRadioButton)
                    .addGroup(AIConfigJPanelLayout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(StartjButton))
                    .addComponent(AIjRadioButton)
                    .addComponent(PlayerjRadioButton)
                    .addComponent(jLabel31)
                    .addComponent(jLabel32)
                    .addComponent(MediumjRadioButton))
                .addContainerGap(65, Short.MAX_VALUE))
        );
        AIConfigJPanelLayout.setVerticalGroup(
            AIConfigJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AIConfigJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel31)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(AIjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PlayerjRadioButton)
                .addGap(18, 18, 18)
                .addComponent(jLabel32)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TouristjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(EasyjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MediumjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(HardjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ExtremejRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addComponent(StartjButton)
                .addContainerGap())
        );

        Status.setFont(new java.awt.Font("Tahoma", 0, 18));
        Status.setForeground(new java.awt.Color(255, 0, 0));
        Status.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        ModejLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        ModejLabel.setForeground(new java.awt.Color(0, 0, 153));
        ModejLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        waitingjProgressBar.setIndeterminate(true);

        waitingjLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        waitingjLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        waitingjLabel.setText("calculating the next move ...");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(Status, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(AIConfigJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ModejLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(waitingjProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(waitingjLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(DropjPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(StatejPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(50, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(DropjPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(StatejPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Status, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29)
                        .addComponent(AIConfigJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ModejLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(waitingjLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(waitingjProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void AIjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AIjRadioButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_AIjRadioButtonActionPerformed

private void EasyjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EasyjRadioButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_EasyjRadioButtonActionPerformed

private void TouristjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TouristjRadioButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_TouristjRadioButtonActionPerformed

public void runAI(State initState)
{
    //initState.display();
    this.AI_nextstep_row = -1;
    this.AI_nextstep_column = -1;
    //get max value for AI
    int val = runMinimaxSearch(initState,1,"max",Integer.MAX_VALUE);//can not prune the first level
    System.out.println(val+" "+this.AI_nextstep_row+" "+this.AI_nextstep_column);
    //mark on the board
    this.Board[this.AI_nextstep_row][this.AI_nextstep_column] = 100;
    this.LabelState[this.AI_nextstep_row][this.AI_nextstep_column].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-green.png")));
    if(AI_win()){
        this.DropjButton1.setEnabled(false);
        this.DropjButton2.setEnabled(false);
        this.DropjButton3.setEnabled(false);
        this.Status.setText("You Lose!");
        return;
    }
}


//parent_val is used for Alpha-Beta Pruning
private int runMinimaxSearch(State s,int depth,String step,int parent_val)
{
    Vector<State> AllStates =  s.getAllNeighborStates(step);
    if(depth>this.depth || AllStates.isEmpty() || s.getScore() == ConnectThreeUtility.PLAYER_WIN || s.getScore() == ConnectThreeUtility.AI_WIN)
        return s.getScore();
    int val;
    if(step.compareTo("max")==0)
    {
        //this is max step
        val = Integer.MIN_VALUE;
        for(int i=0;i<AllStates.size();i++)
        {
            int tmp = runMinimaxSearch(AllStates.elementAt(i),depth+1,"min",val);
            //beta pruning
            if(tmp>=parent_val)
                return parent_val;
            if(val<tmp)
            {
               val = tmp;
               if(depth==1){
                   this.AI_nextstep_row = AllStates.elementAt(i).h_chosen_circle_row;
                   this.AI_nextstep_column = AllStates.elementAt(i).h_chosen_circle_column;
               }
            }
        }
    }
    else
    {
        //this is min step
        val = Integer.MAX_VALUE;
        for(int i=0;i<AllStates.size();i++)
        {
          int tmp = runMinimaxSearch(AllStates.elementAt(i),depth+1,"max",val);
          //alpha pruning
          if(tmp<=parent_val)
              return parent_val;
          if(val>tmp)
              val = tmp;
        }
    }
    return val;
}

private void StartjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartjButtonActionPerformed
// TODO add your handling code here:
    /* Tourist  : depth = 1
     * Easy     : depth = 2
     * Medium   : depth = 5
     * Hard     : depth = 10
     * Extreme  : depth = 29
     * */
    if(this.TouristjRadioButton.isSelected()){
        this.depth = 1;
        this.ModejLabel.setText("Tourist");
    }
    else if(this.EasyjRadioButton.isSelected()){
        this.depth = 2;
        this.ModejLabel.setText("Easy");
    }
    else if(this.MediumjRadioButton.isSelected()){
        this.depth = 4;
        this.ModejLabel.setText("Medium");
    }
    else if(this.HardjRadioButton.isSelected()){
        this.depth = 6;
        this.ModejLabel.setText("Hard");
    }
    else{
        this.depth = 29;
        this.ModejLabel.setText("Extreme");
    }
    
    for(int i=0;i<10;i++)
        for(int j=0;j<3;j++){
            this.Board[i][j] = 0;
            this.LabelState[i][j].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-black.jpg")));
        }
    this.Status.setText("");
    this.DropjButton1.setEnabled(true);
    this.DropjButton2.setEnabled(true);
    this.DropjButton3.setEnabled(true);
    this.DropjPanel.setVisible(true);
    this.StatejPanel.setVisible(true);
    this.StartjButton.setText("Restart");
    if(this.AIjRadioButton.isSelected()){
        task = new Task(this);
        task.execute();
    }
}//GEN-LAST:event_StartjButtonActionPerformed

private boolean AI_win()
{
    for(int i=9;i>=0;i--)
        for(int j=0;j<3;j++)
        {
                //left to right
                if(j+1<3 && j+2<3){
                    if(this.Board[i][j] + this.Board[i][j+1] + this.Board[i][j+2] == 300)
                        return true;
                }
                
                //down to up
                if(i-1>=0 && i-2>=0){
                    if(this.Board[i][j] + this.Board[i-1][j] + this.Board[i-2][j] == 300)
                        return true;
                }
                
                //bottom-right to upper-left
                if(i-1>=0 && j-1>=0 && i-2>=0&&j-2>=0){
                    if(this.Board[i][j] + this.Board[i-1][j-1] + this.Board[i-2][j-2] == 300)
                        return true;
                }
                
                //bottom-left to upper-right
                if(i-1>=0 && j+1<3 && i-2>=0&&j+2<3){
                    if(this.Board[i][j] + this.Board[i-1][j+1] + this.Board[i-2][j+2] == 300)
                        return true;
                }
        }
    return false;
}

private boolean user_win()
{
    for(int i=9;i>=0;i--)
        for(int j=0;j<3;j++)
        {
                //left to right
                if(j+1<3 && j+2<3){
                    if(this.Board[i][j] + this.Board[i][j+1] + this.Board[i][j+2] == 3)
                        return true;
                }
                
                //down to up
                if(i-1>=0 && i-2>=0){
                    if(this.Board[i][j] + this.Board[i-1][j] + this.Board[i-2][j] == 3)
                        return true;
                }
                
                //bottom-right to upper-left
                if(i-1>=0 && j-1>=0 && i-2>=0&&j-2>=0){
                    if(this.Board[i][j] + this.Board[i-1][j-1] + this.Board[i-2][j-2] == 3)
                        return true;
                }
                
                //bottom-left to upper-right
                if(i-1>=0 && j+1<3 && i-2>=0&&j+2<3){
                    if(this.Board[i][j] + this.Board[i-1][j+1] + this.Board[i-2][j+2] == 3)
                        return true;
                }
        }
    return false;
}

private void DropjButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DropjButton1ActionPerformed
// TODO add your handling code here:
    for(int i=9;i>=0;i--)
        if(this.Board[i][0]==0)
        {
            this.LabelState[i][0].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-orange.png")));
            this.Board[i][0] = 1;
            if(user_win()){
                this.DropjButton1.setEnabled(false);
                this.DropjButton2.setEnabled(false);
                this.DropjButton3.setEnabled(false);
                this.Status.setText("You Win!");
                return;
            }
            task = new Task(this);
            task.execute();
            break;
        }
}//GEN-LAST:event_DropjButton1ActionPerformed

private void DropjButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DropjButton2ActionPerformed
// TODO add your handling code here:
    for(int i=9;i>=0;i--)
        if(this.Board[i][1]==0)
        {
            this.LabelState[i][1].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-orange.png")));
            this.Board[i][1] = 1;
            if(user_win()){
                this.DropjButton1.setEnabled(false);
                this.DropjButton2.setEnabled(false);
                this.DropjButton3.setEnabled(false);
                this.Status.setText("You Win!");
                return;
            }
            task = new Task(this);
            task.execute();
            break;
        }
}//GEN-LAST:event_DropjButton2ActionPerformed

private void DropjButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DropjButton3ActionPerformed
// TODO add your handling code here:
    for(int i=9;i>=0;i--)
        if(this.Board[i][2]==0)
        {
            this.LabelState[i][2].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle-orange.png")));
            this.Board[i][2] = 1;
            if(user_win()){
                this.DropjButton1.setEnabled(false);
                this.DropjButton2.setEnabled(false);
                this.DropjButton3.setEnabled(false);
                this.Status.setText("You Win!");
                return;
            }
            task = new Task(this);
            task.execute();
            break;
        }
}//GEN-LAST:event_DropjButton3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ConnectThree.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ConnectThree.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ConnectThree.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ConnectThree.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ConnectThree().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup AIConfigButtonGroup;
    private javax.swing.JPanel AIConfigJPanel;
    public javax.swing.JRadioButton AIjRadioButton;
    private javax.swing.JLabel CirclejLabel0;
    private javax.swing.JLabel CirclejLabel1;
    private javax.swing.JLabel CirclejLabel10;
    private javax.swing.JLabel CirclejLabel11;
    private javax.swing.JLabel CirclejLabel12;
    private javax.swing.JLabel CirclejLabel13;
    private javax.swing.JLabel CirclejLabel14;
    private javax.swing.JLabel CirclejLabel15;
    private javax.swing.JLabel CirclejLabel16;
    private javax.swing.JLabel CirclejLabel17;
    private javax.swing.JLabel CirclejLabel18;
    private javax.swing.JLabel CirclejLabel19;
    private javax.swing.JLabel CirclejLabel2;
    private javax.swing.JLabel CirclejLabel20;
    private javax.swing.JLabel CirclejLabel21;
    private javax.swing.JLabel CirclejLabel22;
    private javax.swing.JLabel CirclejLabel23;
    private javax.swing.JLabel CirclejLabel24;
    private javax.swing.JLabel CirclejLabel25;
    private javax.swing.JLabel CirclejLabel26;
    private javax.swing.JLabel CirclejLabel27;
    private javax.swing.JLabel CirclejLabel28;
    private javax.swing.JLabel CirclejLabel29;
    private javax.swing.JLabel CirclejLabel3;
    private javax.swing.JLabel CirclejLabel4;
    private javax.swing.JLabel CirclejLabel5;
    private javax.swing.JLabel CirclejLabel6;
    private javax.swing.JLabel CirclejLabel7;
    private javax.swing.JLabel CirclejLabel8;
    private javax.swing.JLabel CirclejLabel9;
    public javax.swing.JButton DropjButton1;
    public javax.swing.JButton DropjButton2;
    public javax.swing.JButton DropjButton3;
    private javax.swing.JPanel DropjPanel;
    private javax.swing.JRadioButton EasyjRadioButton;
    private javax.swing.JRadioButton ExtremejRadioButton;
    private javax.swing.JRadioButton HardjRadioButton;
    private javax.swing.JRadioButton MediumjRadioButton;
    private javax.swing.JLabel ModejLabel;
    private javax.swing.ButtonGroup PlayFirstButtonGroup;
    private javax.swing.JRadioButton PlayerjRadioButton;
    private javax.swing.JButton StartjButton;
    private javax.swing.JPanel StatejPanel;
    private javax.swing.JLabel Status;
    private javax.swing.JRadioButton TouristjRadioButton;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    public javax.swing.JLabel waitingjLabel;
    public javax.swing.JProgressBar waitingjProgressBar;
    // End of variables declaration//GEN-END:variables
}
